package formula.web.twork;

import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
import javax.faces.event.ActionListener;

import org.slf4j.LoggerFactory;

public class LogActionListener implements ActionListener {

	private final ActionListener original;
	private final org.slf4j.Logger logger = LoggerFactory.getLogger(getClass());

	public LogActionListener(ActionListener original) {
		this.original = original;
	}

	// public void processAction(ActionEvent event) throws AbortProcessingException {
	// String viewId = FacesContext.getCurrentInstance().getViewRoot().getViewId();
	// String componentId = event.getComponent().getId();
	// String time = new Date().toString();
	// System.out.println("Component " + componentId + " is clicked at page " + viewId + " on " +
	// time);
	// this.original.processAction(event);
	// }
	/**
	 * triggered only on action= method, not on actiobListener (too bad!)
	 */
	@Override
	public void processAction(ActionEvent event) throws AbortProcessingException {
		String viewId = FacesContext.getCurrentInstance().getViewRoot().getViewId();
		String componentId = event.getComponent().getId();
		logger.debug("Component {} is clicked at page {}", componentId, viewId);
		this.original.processAction(event);
	}
}
